<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>QUnit for ASN1 Encoder Class 'asn1x509.js'</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />

<script src="../ext/cj/cryptojs-312-core-fix.js"></script>
<script src="../ext/cj/x64-core.js"></script>
<script src="../ext/cj/cipher-core_min.js"></script>
<script src="../ext/cj/aes_min.js"></script>
<script src="../ext/cj/tripledes_min.js"></script>
<script src="../ext/cj/enc-base64_min.js"></script>
<script src="../ext/cj/md5_min.js"></script>
<script src="../ext/cj/sha1_min.js"></script>
<script src="../ext/cj/sha256_min.js"></script>
<script src="../ext/cj/sha224_min.js"></script>
<script src="../ext/cj/sha512_min.js"></script>
<script src="../ext/cj/sha384_min.js"></script>
<script src="../ext/cj/ripemd160_min.js"></script>
<script src="../ext/cj/hmac_min.js"></script>
<script src="../ext/cj/pbkdf2_min.js"></script>

<script src="../ext/yahoo.js"></script>
<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/base64.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>
<script src="../src/base64x-1.1.js"></script>
<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/rsapem-1.1.js"></script>
<script src="../src/rsasign-1.2.js"></script>
<script src="../src/crypto-1.1.js"></script>
<script src="../src/asn1-1.0.js"></script>
<script src="../src/asn1x509-1.0.js"></script>
<script src="../src/x509-1.1.js"></script>
<script src="../src/keyutil-1.0.js"></script>

<script type="text/javascript">
<!--
$(document).ready(function(){

// ======= TEST ===============================================================

// _test/z4.tsa.cer
var z4TSACERT = 
"-----BEGIN CERTIFICATE-----\n" + 
"MIIDETCCAfmgAwIBAgIBTTANBgkqhkiG9w0BAQUFADAbMQswCQYDVQQGEwJVUzEM\n" + 
"MAoGA1UECgwDQ0ExMB4XDTEzMDUwMTIzNTk1OVoXDTIzMDUwMTIzNTk1OVowHDEL\n" + 
"MAkGA1UEBhMCVVMxDTALBgNVBAMMBFRTQTEwggEiMA0GCSqGSIb3DQEBAQUAA4IB\n" + 
"DwAwggEKAoIBAQDfdOqotHd55SYO0dLz2oXengw/tZ+q3ZmOPeVmMuOMIYO/Cv1w\n" + 
"k2U0OK4pug4OBSJPhl09Zs6IwB8NwPOU7EDTgMOcQUYB/6QNCI1J7Zm2oLtuchzz\n" + 
"4pIb+o4ZAhVprLhRyvqi8OTKQ7kfGfs5Tuwmn1M/0fQkfzMxADpjOKNgf0uy6lN6\n" + 
"utjdTrPKKFUQNdc6/Ty8EeTnQEwUlsT2LAXCfEKxTn5RlRljDztS7Sfgs8VL0FPy\n" + 
"1Qi8B+dFcgRYKFrcpsVaZ1lBmXKsXDRu5QR/Rg3f9DRq4GR1sNH8RLY9uApMl2SN\n" + 
"z+sR4zRPG85R/se5Q06Gu0BUQ3UPm67ETVZLAgMBAAGjXzBdMAwGA1UdEwEB/wQC\n" + 
"MAAwCwYDVR0PBAQDAgbAMBYGA1UdJQEB/wQMMAoGCCsGAQUFBwMIMCgGA1UdHwQh\n" + 
"MB8wHaAboBmGF2h0dHA6Ly90ZXN0LmNvbS9jYTEuY3JsMA0GCSqGSIb3DQEBBQUA\n" + 
"A4IBAQBNkm5GniFi3PKqbafCVN8mpHWJjF2stCRTVxeTCIXUC63YD5XKABGzPH+Y\n" + 
"2R8fCrOa8cGlHmFXOlJye/lnXeZodPyxJUvAKohTp6sG+rJVId8ISI2Io2i5BF8a\n" + 
"CHdm8qd8E0fJvBudqkEc26Ia6tFSA/gEW0ffhsCkN/lXUAjuvDLqtTtU7zBU6dIl\n" + 
"h12Pwyf+x6AsYSciA9zWC6OE590K8Jr2z4u85biM7viWvPeZPNHSNM1fe+8wKbP8\n" + 
"64JtLj/VrglcsXALaUalyh2Hs7gPQzjyus1fyhEWPO3T6KMcBMXjb6anxL5q9YO5\n" + 
"qx1hJTY3L1hahBcMTALQyTEiFv1S\n" + 
"-----END CERTIFICATE-----\n";

test("Certificate class test", function() {
  var pubKey = new RSAKey();
  pubKey.setPublic('e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a', '10001');

  var o = new KJUR.asn1.x509.TBSCertificate();
  o.setSerialNumberByParam({'int': 4});
  o.setSignatureAlgByParam({'name': 'SHA1withRSA'});
  o.setIssuerByParam({'str': '/C=US/O=a'});
  o.setNotBeforeByParam({'str': '130504235959Z'});
  o.setNotAfterByParam({'str': '140504235959Z'});
  o.setSubjectByParam({'str': '/C=US/CN=b'});
  o.setSubjectPublicKey(pubKey);
  o.appendExtension(new KJUR.asn1.x509.BasicConstraints({'cA':true}));
  o.appendExtension(new KJUR.asn1.x509.KeyUsage({'bin':'11'}));

  var prvKey = new RSAKey();
  prvKey.readPKCS5PrvKeyHex("3082013a020100024100e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a4e3518fd590203010001024078bbc54c646795e9a623cb0f912c7f9f6861711560e57bade21ded2f7d9579f86272fab9e71ab27282c2760c404dae6ac8a3ab852cf6bcd562f9aff8247a264d022100fe9bd450866b3255614fde976a76ac0b1d5830dda64f5359b946d8512bc1239f022100e9ab680f5f05dbb0f4311b0e6f4368f4874a1238979d8bc600c35c6f20707c07022100d549cb698dc17d4fe30e5a84f3ade860033c1eeb7f67d286465c9fd817d45b3702201849b4bb44493b989d092da2c675df46eb790b83ce5e95d4b2e79b88017b2fa902207d261a96256d49b020cb1d587ecde127e093a4d2b34cdbff171f34125b5857a9");
  var crt1 = new KJUR.asn1.x509.Certificate({tbscertobj: o,
                                             prvkeyobj:  prvKey});
  crt1.sign();					  
  expect(3);
  // test3
  equal(crt1.asn1TBSCert.getEncodedHex(), "3081e5a003020102020104300d06092a864886f70d01010505003019310b3009060355040613025553310a3008060355040a0c0161301e170d3133303530343233353935395a170d3134303530343233353935395a3019310b3009060355040613025553310a300806035504030c01623057300d06092a864886f70d01010105000346003043023c00e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a0203010001a31d301b300c0603551d13040530030101ff300b0603551d0f0404030206c0", "constructor,sign,asn1TBSCert.getEncodedHex");

  // test1
  hCrt1 = crt1.getEncodedHex()
  equal(hCrt1, "3082013a3081e5a003020102020104300d06092a864886f70d01010505003019310b3009060355040613025553310a3008060355040a0c0161301e170d3133303530343233353935395a170d3134303530343233353935395a3019310b3009060355040613025553310a300806035504030c01623057300d06092a864886f70d01010105000346003043023c00e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a0203010001a31d301b300c0603551d13040530030101ff300b0603551d0f0404030206c0300d06092a864886f70d010105050003410088dca030a5dcae7b85f0bfcb1fcbac18065d9f5bfd717c78075449a8447e87d0c7cb0cfd2b2ad7140c4075fd44b741502b89a7f7a9967e21c8aea330ac124be0", "constructor,sign,getEncodedHex");

  // test2
  equal(crt1.getPEMString(), "-----BEGIN CERTIFICATE-----\r\nMIIBOjCB5aADAgECAgEEMA0GCSqGSIb3DQEBBQUAMBkxCzAJBgNVBAYTAlVTMQow\r\nCAYDVQQKDAFhMB4XDTEzMDUwNDIzNTk1OVoXDTE0MDUwNDIzNTk1OVowGTELMAkG\r\nA1UEBhMCVVMxCjAIBgNVBAMMAWIwVzANBgkqhkiG9w0BAQEFAANGADBDAjwA6GZN\r\n0rQFKRIVaPOzm8l6Yue6PAm6vcTw3NjfkOt5C5u2RaK3DjESdHtNPEG1FCSJURX+\r\n+I951D6uWxoCAwEAAaMdMBswDAYDVR0TBAUwAwEB/zALBgNVHQ8EBAMCBsAwDQYJ\r\nKoZIhvcNAQEFBQADQQCI3KAwpdyue4Xwv8sfy6wYBl2fW/1xfHgHVEmoRH6H0MfL\r\nDP0rKtcUDEB1/US3QVAriaf3qZZ+IciuozCsEkvg\r\n-----END CERTIFICATE-----\r\n", "getPEMString");


});

test("TBSCertificate class test", function() {
  expect(1);

  var rsaKey = new RSAKey();
  rsaKey.setPublic('e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a', '10001');

  var o = new KJUR.asn1.x509.TBSCertificate();
  o.setSerialNumberByParam({'int': 4});
  o.setSignatureAlgByParam({'name': 'SHA1withRSA'});
  o.setIssuerByParam({'str': '/C=US/O=a'});
  o.setNotBeforeByParam({'str': '130504235959Z'});
  o.setNotAfterByParam({'str': '140504235959Z'});
  o.setSubjectByParam({'str': '/C=US/CN=b'});
  o.setSubjectPublicKey(rsaKey);
  o.appendExtension(new KJUR.asn1.x509.BasicConstraints({'cA':true}));
  o.appendExtension(new KJUR.asn1.x509.KeyUsage({'bin':'11'}));

  equal(o.getEncodedHex(), "3081e5a003020102020104300d06092a864886f70d01010505003019310b3009060355040613025553310a3008060355040a0c0161301e170d3133303530343233353935395a170d3134303530343233353935395a3019310b3009060355040613025553310a300806035504030c01623057300d06092a864886f70d01010105000346003043023c00e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a0203010001a31d301b300c0603551d13040530030101ff300b0603551d0f0404030206c0", "set/append test1");
});

test("X500Name class test", function() {
  var o = null;

  o = new KJUR.asn1.x509.X500Name();
  o.setByString("/C=US/O=aaa");
  equal(o.getEncodedHex(), 
         "301b310b3009060355040613025553310c300a060355040a0c03616161",
         "setByString(/C=US/O=aaa)");

  o = new KJUR.asn1.x509.X500Name();
  o.setByString("/C=US/O=あ");
  equal(o.getEncodedHex(), 
         "301b310b3009060355040613025553310c300a060355040a0c03e38182",
         "setByString(/C=US/O=あ)");

  o = new KJUR.asn1.x509.X500Name();
  o.setByObject({C: "US", O: "aaa"});
  equal(o.getEncodedHex(), 
         "301b310b3009060355040613025553310c300a060355040a0c03616161",
         "setByObject({C: 'US', O: 'aaa'})");

  o = new KJUR.asn1.x509.X500Name({'str':'/C=US/O=aaa'});
  equal(o.getEncodedHex(),
         "301b310b3009060355040613025553310c300a060355040a0c03616161",
         "constructor str /C=US/O=aaa");

  o = new KJUR.asn1.x509.X500Name({'C': 'US', 'O': 'aaa'});
  equal(o.getEncodedHex(),
         "301b310b3009060355040613025553310c300a060355040a0c03616161",
         "constructor obj C:US, O:aaa");

  o = new KJUR.asn1.x509.X500Name({'C': 'US', 'O': 'aa/'});
  equal(o.getEncodedHex(),
         "301b310b3009060355040613025553310c300a060355040a0c0361612f",
         "constructor obj C:US, O:aa/");

  o = new KJUR.asn1.x509.X500Name({'str': '/O=a/O=b/b/O=c/c/c'});
  equal(o.getEncodedHex(),
         "302a310a3008060355040a0c0161310c300a060355040a0c03622f62310e300c060355040a0c05632f632f63",
         "constructor str /O=a/O=b/b/O=c/c/c");
});

test("RDN class test", function() {
  expect(2);
  var o2 = new KJUR.asn1.x509.RDN();
  o2.addByString("O=aaa");
  equal(o2.getEncodedHex(), "310c300a060355040a0c03616161", "addByString(O=aaa)");

  var o3 = new KJUR.asn1.x509.RDN({'str':'O=aaa'});
  equal(o3.getEncodedHex(), "310c300a060355040a0c03616161", "constructor str O=aaa");
});

test("AttributeTypeAndValue class test", function() {
  var o1 = new KJUR.asn1.x509.AttributeTypeAndValue();
  o1.setByAttrTypeAndValueStr("O", "aaa");
  equal(o1.getEncodedHex(), "300a060355040a0c03616161", "setByAttrTypeAndValueStr O aaa");

  var o2 = new KJUR.asn1.x509.AttributeTypeAndValue();
  o2.setByString("O=aaa");
  equal(o2.getEncodedHex(), "300a060355040a0c03616161", "setByString(O=aaa)");

  var o3 = new KJUR.asn1.x509.AttributeTypeAndValue({'str':'O=aaa'});
  equal(o3.getEncodedHex(), "300a060355040a0c03616161", "constructor str O=aaa");

  var o4 = new KJUR.asn1.x509.AttributeTypeAndValue({'str':'O=あ'});
  equal(o4.getEncodedHex(), "300a060355040a0c03e38182", "constructor str O=あ");
});

// === BEGIN Other ASN1 structure class  ======================================

test("SubjectPublicKeyInfo class test", function() {
  var rsaKey = new RSAKey();
  rsaKey.setPublic('e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a', '10001');
  var o1 = new KJUR.asn1.x509.SubjectPublicKeyInfo(rsaKey);
  equal(o1.getEncodedHex(), "3057300d06092a864886f70d01010105000346003043023c00e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a0203010001", "constructor default rsaKey");

  var pubpem2 =
    "-----BEGIN PUBLIC KEY-----\n" +
    "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAOtpGHibL8Ue+MXPPufkcrNES40rCT5L\n" +
    "RIU9MjTZ8/7owG5bAsiFA9Xxh3uZK1T5QA64jNJVbp2ojHAtNyWPuwsCAwEAAQ==" +
    "-----END PUBLIC KEY-----\n" 
  var pubobj2 = KEYUTIL.getKey(pubpem2);
  var o2 = new KJUR.asn1.x509.SubjectPublicKeyInfo();
  o2.setPubKey(pubobj2);
  equal(o2.getEncodedHex(), "305c300d06092a864886f70d0101010500034b003048024100eb6918789b2fc51ef8c5cf3ee7e472b3444b8d2b093e4b44853d3234d9f3fee8c06e5b02c88503d5f1877b992b54f9400eb88cd2556e9da88c702d37258fbb0b0203010001", "pubpem2");
});

test("Time class test", function() {
  expect(4);

  var o1 = new KJUR.asn1.x509.Time({'str':'130430235959Z'}); // UTC
  equal(o1.getEncodedHex(), "170d3133303433303233353935395a", "constructor default timestr");

  var o2 = new KJUR.asn1.x509.Time({'str':'20130430235959Z', 'type': 'gen'}); // Gen
  equal(o2.getEncodedHex(), "180f32303133303433303233353935395a", "constructor default timestr");

  var o3 = new KJUR.asn1.x509.Time({'str':'20130430235959Z'}); // Gen
  equal(o3.getEncodedHex(), "180f32303133303433303233353935395a", "constructor default timestr (auto gen)");

  var o4 = new KJUR.asn1.x509.Time(); // auto UTC
  equal(o4.getEncodedHex().substr(0, 4), "170d", "constructor default timestr (empty)=170d...");
});

test("AlgorithmIdentifier class test", function() {
  equal(new KJUR.asn1.x509.AlgorithmIdentifier({'name':'SHA1withRSA'}).getEncodedHex(),
        "300d06092a864886f70d0101050500", "constructor name SHA1withRSA");

  equal(new KJUR.asn1.x509.AlgorithmIdentifier({'name':'SHA256withRSA'}).getEncodedHex(),
        "300d06092a864886f70d01010b0500", "constructor name SHA256withRSA");

  equal(new KJUR.asn1.x509.AlgorithmIdentifier({'name':'SHA256withRSA', paramempty: true}).getEncodedHex(),
        "300b06092a864886f70d01010b", "constructor name SHA256withRSA, paramempty");

  equal(new KJUR.asn1.x509.AlgorithmIdentifier({'name':'SHA1withDSA'}).getEncodedHex(),
        "300906072a8648ce380403", "constructor name SHA1withDSA");

  equal(new KJUR.asn1.x509.AlgorithmIdentifier({'name':'SHA512withECDSA'}).getEncodedHex(),
        "300a06082a8648ce3d040304", "constructor name SHA512withECDSA");

  equal(new KJUR.asn1.x509.AlgorithmIdentifier({'name':'rsaEncryption'}).getEncodedHex(),
        "300d06092a864886f70d0101010500", "constructor name rsaEncryption");

  equal(new KJUR.asn1.x509.AlgorithmIdentifier({'name':'sha1'}).getEncodedHex(),
        "300906052b0e03021a0500", "constructor name sha1");
});

test("AlgorithmIdentifier SHA1withECDSA", function() {
var o = new KJUR.asn1.x509.AlgorithmIdentifier({name: 'SHA1withECDSA', paramempty: true});
equal(o.getEncodedHex(), "300906072a8648ce3d0401", "aaa");
});

test("AlgorithmIdentifier SHA256withECDSA", function() {
var o = new KJUR.asn1.x509.AlgorithmIdentifier({name: 'SHA256withECDSA', paramempty: true});
equal(o.getEncodedHex(), "300a06082a8648ce3d040302", "aaa");
});

test("AlgorithmIdentifier SHA1withDSA", function() {
var o = new KJUR.asn1.x509.AlgorithmIdentifier({name: 'SHA1withDSA', paramempty: true});
equal(o.getEncodedHex(), "300906072a8648ce380403", "aaa");
});

test("AlgorithmIdentifier SHA256withDSA", function() {
var o = new KJUR.asn1.x509.AlgorithmIdentifier({name: 'SHA256withDSA', paramempty: true});
equal(o.getEncodedHex(), "300b0609608648016503040302", "aaa");
});

test("GeneralName class test", function() {
  var o;
  o = new KJUR.asn1.x509.GeneralName({'rfc822':'u1@foo.com'});
  equal(o.getEncodedHex(), "810a753140666f6f2e636f6d", "constructor rfc822 u1@foo.com");

  o = new KJUR.asn1.x509.GeneralName({'dns':'foo.com'});
  equal(o.getEncodedHex(), "8207666f6f2e636f6d", "constructor dns foo.com");

  o = new KJUR.asn1.x509.GeneralName({'uri':'http://aaa.com/'});
  equal(o.getEncodedHex(), "860f687474703a2f2f6161612e636f6d2f", "constructor uri http://aaa.com/");

  o = new KJUR.asn1.x509.GeneralName({certissuer: z4TSACERT});
  equal(o.getEncodedHex(), "a41d301b310b3009060355040613025553310c300a060355040a0c03434131", "constructor certissuer cert1");

  o = new KJUR.asn1.x509.GeneralName({certsubj: z4TSACERT});
  equal(o.getEncodedHex(), "a41e301c310b3009060355040613025553310d300b06035504030c0454534131", "constructor certsubj cert1");

  o = new KJUR.asn1.x509.GeneralName({dn: '/C=US/O=Test'});
  equal(o.getEncodedHex(), "a41e301c310b3009060355040613025553310d300b060355040a0c0454657374", "dn /C=US/O=Test");

  o = new KJUR.asn1.x509.GeneralName({ldapdn: 'O=Test,C=US'});
  equal(o.getEncodedHex(), "a41e301c310b3009060355040613025553310d300b060355040a0c0454657374", "ldapdn O=Test,C=US");

  o = new KJUR.asn1.x509.GeneralName({ip: '192.168.1.1'});
  equal(o.getEncodedHex(), "8704c0a80101", "ip: 192.168.1.1");

  o = new KJUR.asn1.x509.GeneralName({ip: '2001:db8::4'});
  equal(o.getEncodedHex(), "871020010db8000000000000000000000004", "ip: 2001:db8::4");

  o = new KJUR.asn1.x509.GeneralName({ip: '2606:4700:4700::1111'});
  equal(o.getEncodedHex(), "871026064700470000000000000000001111", "ip: 2606:4700:4700::1111");

  o = new KJUR.asn1.x509.GeneralName({ip: 'c0a80101'});
  equal(o.getEncodedHex(), "8704c0a80101", "ip: c0a80101");
});

test("GeneralNames class test", function() {
  expect(1);
  var o1 = new KJUR.asn1.x509.GeneralNames([{'uri':'http://aaa.com/'}]);
  equal(o1.getEncodedHex(), "3011860f687474703a2f2f6161612e636f6d2f", "constructor uri http://aaa.com/");
});

test("DistributionPointName class test", function() {
  expect(1);
  var o1a = new KJUR.asn1.x509.GeneralNames([{'uri':'http://aaa.com/'}]);
  var o1 = new KJUR.asn1.x509.DistributionPointName(o1a);
  equal(o1.getEncodedHex(), "a011860f687474703a2f2f6161612e636f6d2f", "constructor uri http://aaa.com/");
});

test("DistributionPoint class test", function() {
  expect(1);
  var o1aa = new KJUR.asn1.x509.GeneralNames([{'uri':'http://aaa.com/'}]);
  var o1a = new KJUR.asn1.x509.DistributionPointName(o1aa);
  var o1 = new KJUR.asn1.x509.DistributionPoint({'dpobj': o1a});
  equal(o1.getEncodedHex(), "3015a013a011860f687474703a2f2f6161612e636f6d2f", "constructor dpobj http://aaa.com/");
});

test("OID class test", function() {
  var o = KJUR.asn1.x509.OID;
  equal(o.atype2obj('C').getEncodedHex(), "0603550406", "C");
  equal(o.name2obj('SHA1withRSA').getEncodedHex(), 
         "06092a864886f70d010105", "name2obj SHA1withRSA");
  equal(o.name2oid('basicConstraints'), '2.5.29.19', "name2oid basicConstraints");
  equal(o.name2oid('UNKNOWNOIDNAME'), '', "name2oid unknown name");
  equal(o.oid2name('2.5.29.19'), 'basicConstraints', "oid2name basicConstraints");
  equal(o.oid2name('0.0.0.0'), '', "oid2name unknown oid");
});

// BasicConstraints
test("BasicConstraints class test", function() {
  expect(6);
  var o1 = new KJUR.asn1.x509.BasicConstraints({});
  equal(o1.getExtnValueHex(), "3000", "constructor cA=f getExtnValueHex");
  equal(o1.getEncodedHex(), "30090603551d1304023000", "constructor cA=f getEncodedHex");

  var o2 = new KJUR.asn1.x509.BasicConstraints({'cA':true});
  equal(o2.getExtnValueHex(), "30030101ff", "constructor cA=t getExtnValueHex");
  equal(o2.getEncodedHex(), "300c0603551d13040530030101ff", "constructor cA=t getEncodedHex");

  var o3 = new KJUR.asn1.x509.BasicConstraints({'cA':true, 'pathLen': 7});
  equal(o3.getExtnValueHex(), "30060101ff020107", "constructor cA=t pl=7 getExtnValueHex");
  equal(o3.getEncodedHex(), "300f0603551d13040830060101ff020107", "constructor cA=t pl=7 getEncodedHex");
});

// KeyUsage
test("KeyUsage class test", function() {
  var o;
  o = new KJUR.asn1.x509.KeyUsage({'bin':'11'});
  equal(o.getExtnValueHex(), "030206c0", "constructor bin 11 getExtnValueHex");
  equal(o.getEncodedHex(), "300b0603551d0f0404030206c0", "constructor bin 11 getEncodedHex");

  o = new KJUR.asn1.x509.KeyUsage({'bin':'11', 'critical': true});
  equal(o.getEncodedHex(), "300e0603551d0f0101ff0404030206c0", "constructor bin 11 critical getEncodedHex");

  o = new KJUR.asn1.x509.KeyUsage({'names': ['digitalSignature', 'nonRepudiation']});
  equal(o.getEncodedHex(), "300b0603551d0f0404030206c0", "constructor names [digitalSignature, nonRepudiation]");

  o = new KJUR.asn1.x509.KeyUsage({'bin':'000000011'});
  equal(o.getEncodedHex(), "300c0603551d0f04050303070180", "constructor bin 000000011");

  o = new KJUR.asn1.x509.KeyUsage({'names': ['encipherOnly', 'decipherOnly']});
  equal(o.getEncodedHex(), "300c0603551d0f04050303070180", "constructor names [encipherOnly, decipherOnly]");
});

// CRLDP
test("CRLDistributionPoints class test", function() {
  expect(2);

  var gn1 = new KJUR.asn1.x509.GeneralNames([{'uri':'http://aaa.com/'}]);
  var dpn1 = new KJUR.asn1.x509.DistributionPointName(gn1);
  var dp1 = new KJUR.asn1.x509.DistributionPoint({'dpobj': dpn1});
  var cdp1 = new KJUR.asn1.x509.CRLDistributionPoints({'array': [dp1]});
  equal(cdp1.getEncodedHex(), "30200603551d1f041930173015a013a011860f687474703a2f2f6161612e636f6d2f", "constructor array http://aaa.com/");

  var cdp2 = new KJUR.asn1.x509.CRLDistributionPoints({'uri': 'http://aaa.com/'});
  equal(cdp2.getEncodedHex(), "30200603551d1f041930173015a013a011860f687474703a2f2f6161612e636f6d2f", "constructor uri http://aaa.com/");
});

// ExtKeyUsage
test("ExtKeyUsage class test", function() {
  expect(1);

 var eku1 = 
 	new KJUR.asn1.x509.ExtKeyUsage({'array':
	                                [{'oid': '2.5.29.37.0'},  // anyExtendedKeyUsage
					 {'name': 'clientAuth'}]});
  equal(eku1.getEncodedHex(), "30190603551d25041230100604551d250006082b06010505070302", "constructor array");
});

// AuthorityKeyIdentifier
test("AuthorityKeyIdentifier class test (KID)", function() {
  expect(2);
  var o1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({'kid': {'hex': '89ab'}});
  equal(o1.getExtnValueHex(), "3004800289ab", "kid value");
  equal(o1.getEncodedHex(), "300d0603551d2304063004800289ab", "ext hex");
});

test("AuthorityKeyIdentifier class test (CertIssuer)", function() {
  expect(2);
  var o1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({'issuer': {'str': '/C=US/CN=a'}});
  equal(o1.getExtnValueHex(), "301ba119310b3009060355040613025553310a300806035504030c0161", "issuer name");
  equal(o1.getEncodedHex(), "30240603551d23041d301ba119310b3009060355040613025553310a300806035504030c0161", "ext hex");
});

test("AuthorityKeyIdentifier class test (CertSN)", function() {
  expect(2);
  var o1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({'sn': {'hex': '1234'}});
  equal(o1.getExtnValueHex(), "300482021234", "cert SN");
  equal(o1.getEncodedHex(), "300d0603551d230406300482021234", "ext hex");
});

test("AuthorityKeyIdentifier class test (All)", function() {
  expect(2);
  var o1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({'kid': {'hex': '89ab'},
                                                      'issuer': {'str': '/C=US/CN=a'},
                                                      'sn': {'hex': '1234'}});
  equal(o1.getExtnValueHex(), "3023800289aba119310b3009060355040613025553310a300806035504030c016182021234", "all");
  equal(o1.getEncodedHex(), "302c0603551d2304253023800289aba119310b3009060355040613025553310a300806035504030c016182021234", "ext hex");
});

test("AuthorityKeyIdentifier class test (KID critical)", function() {
  expect(2);
  var o1 = new KJUR.asn1.x509.AuthorityKeyIdentifier({'kid': {'hex': '89ab'}, 'critical': true});
  equal(o1.getExtnValueHex(), "3004800289ab", "kid critical");
  equal(o1.getEncodedHex(), "30100603551d230101ff04063004800289ab", "ext hex");
});

test("SubjectAltName", function() {
  var o1 = new KJUR.asn1.x509.SubjectAltName({
    critical: true,
    array: [{uri: 'http://a.com'}, {uri: 'http://b.com'}]
  });
  equal(o1.getExtnValueHex(), "301c860c687474703a2f2f612e636f6d860c687474703a2f2f622e636f6d", "URIs critical");
  equal(o1.getEncodedHex(), "30280603551d110101ff041e301c860c687474703a2f2f612e636f6d860c687474703a2f2f622e636f6d", "ext hex");
});

test("IssuerAltName", function() {
  var o1 = new KJUR.asn1.x509.IssuerAltName({
    critical: true,
    array: [{uri: 'http://a.com'}, {uri: 'http://b.com'}]
  });
  equal(o1.getExtnValueHex(), "301c860c687474703a2f2f612e636f6d860c687474703a2f2f622e636f6d", "URIs critical");
  equal(o1.getEncodedHex(), "30280603551d120101ff041e301c860c687474703a2f2f612e636f6d860c687474703a2f2f622e636f6d", "ext hex");
});

// ==== END OF X.509V3 EXTENSION TEST ===================
test("CRL class test", function() {
  expect(1);

  // TBS
  var o = new KJUR.asn1.x509.TBSCertList();
  o.setSignatureAlgByParam({'name': 'SHA1withRSA'});
  o.setIssuerByParam({'str': '/C=US/O=a'});
  o.setThisUpdateByParam({'str': '130504235959Z'});
  o.setNextUpdateByParam({'str': '130604235959Z'});

  var prvKey = new RSAKey();
  prvKey.readPKCS5PrvKeyHex("3082013a020100024100e8664dd2b40529121568f3b39bc97a62e7ba3c09babdc4f0dcd8df90eb790b9bb645a2b70e3112747b4d3c41b51424895115fef88f79d43eae5b1a4e3518fd590203010001024078bbc54c646795e9a623cb0f912c7f9f6861711560e57bade21ded2f7d9579f86272fab9e71ab27282c2760c404dae6ac8a3ab852cf6bcd562f9aff8247a264d022100fe9bd450866b3255614fde976a76ac0b1d5830dda64f5359b946d8512bc1239f022100e9ab680f5f05dbb0f4311b0e6f4368f4874a1238979d8bc600c35c6f20707c07022100d549cb698dc17d4fe30e5a84f3ade860033c1eeb7f67d286465c9fd817d45b3702201849b4bb44493b989d092da2c675df46eb790b83ce5e95d4b2e79b88017b2fa902207d261a96256d49b020cb1d587ecde127e093a4d2b34cdbff171f34125b5857a9");

  var crl1 = new KJUR.asn1.x509.CRL({'tbsobj': o,'prvkeyobj': prvKey});
  crl1.sign();
  equal(crl1.getEncodedHex(), "30819c3048300d06092a864886f70d01010505003019310b3009060355040613025553310a3008060355040a0c0161170d3133303530343233353935395a170d3133303630343233353935395a300d06092a864886f70d0101050500034100161f6e8b3cbe992aa4eece8894516a65d530543c6f23e83860cc391ae8289504cbe91f118fd20e2b96966182f695f9dce27b3e76f7d84beeab293cc3c9649740", "crl sign");
});

test("TBSCertList class test", function() {
  expect(1);
  var o = new KJUR.asn1.x509.TBSCertList();
  o.setSignatureAlgByParam({'name': 'SHA1withRSA'});
  o.setIssuerByParam({'str': '/C=US/O=a'});
  o.setThisUpdateByParam({'str': '130504235959Z'});
  o.setNextUpdateByParam({'str': '130604235959Z'});

  equal(o.getEncodedHex(), "3048300d06092a864886f70d01010505003019310b3009060355040613025553310a3008060355040a0c0161170d3133303530343233353935395a170d3133303630343233353935395a", "constructor");
});

test("TBSCertList 2 class test", function() {
  expect(1);
  var o = new KJUR.asn1.x509.TBSCertList();
  o.setSignatureAlgByParam({'name': 'SHA1withRSA'});
  o.setIssuerByParam({'str': '/C=US/O=a'});
  o.setThisUpdateByParam({'str': '130504235959Z'});
  o.setNextUpdateByParam({'str': '130604235959Z'});
  o.addRevokedCert({'int': 4}, {'str':'130514235959Z'});

  equal(o.getEncodedHex(), "305e300d06092a864886f70d01010505003019310b3009060355040613025553310a3008060355040a0c0161170d3133303530343233353935395a170d3133303630343233353935395a30143012020104170d3133303531343233353935395a", "constructor with revoked cert");
});

test("CRLEntry class test", function() {
  expect(1);
  var e = new KJUR.asn1.x509.CRLEntry({'time':{'str':'130514235959Z'}, 'sn':{'int':3}});
  equal(e.getEncodedHex(), "3012020103170d3133303531343233353935395a", "constructor/1");
});

});
-->
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
<a href="index.html">TEST INDEX</a> |
<a href="qunit-do-x509-hex2dn.html">x509-hex2dn</a> |
<a href="qunit-do-asn1x509.html">asn1x509</a> |
<a href="qunit-do-asn1x509-newcrt.html">asn1x509-newcrt</a> |
<a href="qunit-do-asn1x509-multirdn.html">asn1x509-multirdn</a> |
<a href="qunit-do-asn1csr.html">asn1csr</a> |
</body>
</html>
